// JavaScript Document

$(document).ready(function(e) {
	var headHei=$(".g_head").height();
    $(window).scroll(function(){
		if($(".g_head").length>0){
			if($(window).scrollTop()>headHei){
				$(".g_head").attr("style","position:fixed;top:0;z-index:1000;")
				$("body").css("padding-top","0.8rem");	
			}else{
				$(".g_head").removeAttr("style");
				$("body").css("padding-top",0);
			}	
		}
	})
});

//折线图
function zxtBox(divDx,listDx,dataBdx){
	
	var dataB=dataBdx; //////两条线的数据////////
	
	
	
	var styleX={};
		styleX.left=[]; ////每一列x方面的位置//////
		var maxlen=0;
		for(var i=0;i<dataB.length;i++){
			maxlen=Math.max(maxlen,dataB[i].data.length);
		}
		
		for(var j=0;j<maxlen;j++){
			styleX.left.push(j*50);
			if(j==0){
				$(listDx).append("<li>　"+j+"</li>");	
			}else{
				$(listDx).append("<li>周龄"+j+"</li>");	
			}
			$(listDx).find("li").eq(j).css("left",j*50-10);
			$(listDx).parent().width(maxlen*50);
			
		}
		var styleB={width:(maxlen)*50,height:145}; ////容器属性///
		
		
		styleX.Mdata=100;
		styleX.animtr="easeInOutCubic";
		styleX.animtime=1000;	
		
	createLineGraph($(divDx),dataB,styleB,styleX);
	
	
}





////////功能函数//////
function createLineGraph(content,data,style,stylet){
	var obj=content;
	var svgns = "http://www.w3.org/2000/svg";
	var bilishs=parseInt(style.height)/stylet.Mdata;
	var svg=document.createElementNS(svgns,"svg");
	svg.setAttribute("width",style.width);
	svg.setAttribute("height",style.height);
	for(var i=0;i<data.length;i++){
		var g=document.createElementNS(svgns,"g");
		var linedat="";
		var lineYs="";
		for(var j=0;j<data[i].data.length;j++){
			var dt=data[i].data[j];
			var circle=document.createElementNS(svgns,"circle");
			var x=stylet.left[j];
			var y=(stylet.Mdata-dt)*bilishs;
			var xs=0;
			var ys=100;
			circle.setAttribute("cx",x);
			circle.setAttribute("cy",y);
			circle.setAttribute("fill",data[i].color);
			circle.setAttribute("stroke-width",0);
			circle.setAttribute("r",data[i].R);
			if(linedat!=""){
				linedat+=" ";
				lineYs+=" ";
			}
			linedat+=x+","+y;
			lineYs+=x+","+ys;
			g.appendChild(circle);
		}
		var polyline=document.createElementNS(svgns,"polyline");
		polyline.setAttribute("stroke",data[i].color);
		polyline.setAttribute("stroke-width",data[i].lineW);
		polyline.setAttribute("points",linedat);
		polyline.setAttribute("fill","none");
		//$(polyline).animation({"points",linedat},300)
		g.appendChild(polyline);
		svg.appendChild(g)
	}
	$(svg).css("margin-top","-12px");
	svg.setAttribute("height",style.height+10);
	$(svg).width(0).animate({width:style.width},stylet.animtime,stylet.animtr);
	obj.eq(0)[0].appendChild(svg);
}



//柱状图
 //////功能调用并传入属性/////////


function zhztBox(divDx,colorDx,listDx,lsjDx,maxH,xZhou){
	var dataA=lsjDx; ////////这列是数据////////
	
	
	var styleT={};
		styleT.left=[]; ////每一列x方面的位置//////
		var maxlenz=0;
		for(var i=0;i<dataA.length;i++){
			maxlenz=Math.max(maxlenz,dataA[i].length);
		}
		
		for(var j=0;j<xZhou.length;j++){
			styleT.left.push(j*60);
			if(j==0){
				$(listDx).append("<li>"+(xZhou[j])+"</li>");	
			}else{
				$(listDx).append("<li>"+(xZhou[j])+"</li>");	
			}
			$(listDx).find("li").eq(j).css("left",j*60+8);
			$(listDx).parent().width(xZhou.length*60);
			
		};
		
		
	var styleA={}; ////容器属性///
		styleA.width=(maxlenz)*50;
		styleA.height=128;
		styleA.position="absolute";	
		styleT.color=colorDx;
		styleT.width=9;
		styleT.Mdata=Number(maxH);
		styleT.animtr="easeInOutCubic";
		styleT.animtime=1000;
		
	createHistogram($(divDx),dataA,styleA,styleT);
	
}





////////功能函数//////
function createHistogram(content,data,style,stylet){
	var obj=content;
	var newdiv=$("<div style='height:150px;padding-top:22px'>");
	newdiv.css(style);
	var bilihT=parseInt(style.height)/stylet.Mdata;
	var setIntervss;
	var curhis=0;
	for(var i=0;i<data.length;i++){
		var T=$("<div>");
		T.css({position:"absolute",bottom:0,left:stylet.left[i]+22,width:stylet.width,marginLeft:-stylet.width/2,background:stylet.color,height:0});
		
		T.animate({height:data[i]*bilihT},stylet.animtime/2*Math.random()+stylet.animtime/2,stylet.animtr,function(){
			curhis++;
			if(curhis==data.length){
				clearInterval(setIntervss);
			}
		});
		var Sp=$("<span>")
		Sp.text(0)
		Sp.css({display:"block",fontSize:stylet.width*1.7,color:"#999",top:-stylet.width*2.5,position:"relative",width:stylet.width*5,left:-2*stylet.width,textAlign:"center"})
		T.append(Sp);
		newdiv.append(T);
		T.css("overflow","visible");
	}
	obj.append(newdiv);
	setIntervss=setInterval(setIntervsssel,30);
	function setIntervsssel(){
		newdiv.find("div").each(function(index, element) {
			var thisObj=$(this);
            var thisHt=thisObj.height();
			thisObj.find("span").text(data[index]);
        });
	}

}

//////全局方法////////
function alertS(sty, fun){
	$("body").append('<div class="g_bghui"></div><div class="g_rongliang_tc01"><p>'+sty+'</p><a href="javascript:void(0)" title="" class="g_new_queding">确定</a></div>');
	$(".g_bghui").show();
	$(".g_rongliang_tc01").show();
	
	$(".g_new_queding, .g_btn_close").click(function(){
		$(".g_rongliang_tc01").remove();
		$(".g_bghui").remove();
		if (fun != undefined && fun != "") {
			fun();
		}
	})
}

function confirmS(sty,fun,fun2){
	$("body").append('<div class="g_bghui"></div><div class="g_rongliang_tc"><p>'+sty+'</p><div class="g_tc_btn"><a href="javascript:void(0)" title="" class="g_quxiao">取消</a><a href="javascript:void(0)" title="" class="g_queren">确认</a></div></div>');
	$(".g_bghui").show();
	$(".g_rongliang_tc").show();
	
	$(".g_quxiao").click(function(){
		$(".g_rongliang_tc").remove();
		$(".g_bghui").remove();
		
		if (fun2 != undefined && fun2 != "") {
			fun2();
		}
	})
	
	$(".g_queren").click(function(){
		$(".g_rongliang_tc").remove();
		$(".g_bghui").remove();
		fun();
	})
}

function formatDate (strTime) {
    var date = new Date(strTime);
    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
}